Ext.namespace("Portal");

Portal.mapping = {
	'unfinishedTask': 'task/taskExecut.html?opentab=unfinished',
	'noteTask': 'report/hallManager-view.jsp',
	'takenTask': 'task/taskExecut.html',
	'expiredTask': 'task/taskExecut.html?opentab=unfinished&outTime=1',
	'planing': 'plan/planAdd.html?opentab=toaudit',
	'auditPlan': 'plan/planAuditList.html',
	'deptTask': 'task/taskExecut.html?opentab=deptTask',
	'needFeedBack': 'task/taskExecut.html?opentab=needFeedBack',
	'monitorUnfinishedTask':'./task/taskWatch.html',
	'monitorWeekTask':'./task/taskWatch.html',
	'monitorMonthTask':'./task/taskWatch.html',
	'dispatchFinished':'./task/taskWatch.html',
	'dispatchUnFinished':'./task/taskWatch.html'
};
Portal.model = {
	'unfinishedTask': '我的任务',
	'takenTask': '我的任务',
	'planing': '我的计划',
	'auditPlan': '我的计划'
};

Portal.updateTheme = function() {
	var theme = Utils.getParameter('theme');
	if (!theme) theme = 'blue';
	var lists = Ext.get(Ext.query('.list'));
	lists.addClass(theme);
};

Portal.open = function(e,t,o) {
	var p = Utils.getParent();
	if (p === null) return;
	var id = t.id;
	// Note: parent.go is TD Script
	p.go(Portal.model[id], Portal.mapping[id]);	// Call TD Script
};

Portal.update = function(id, n) {
	var span = Ext.get(id);
	span.update(n);
		span.addClass('highlight');
		span.addListener('click', Portal.open);
};

Portal.conn = new Ext.data.Connection({
	url: Utils.formatURL('./portal/message.form'),
	method: 'POST'
});

Portal.main = function() {
	Portal.updateTheme();
	Utils.request(Portal.conn, {
		params: {},
		success: function(resp, action) {
			if (!resp || !resp.success) return;
			Portal.update('noteTask', resp.noteTask);
			Portal.update('unfinishedTask', resp.unfinishedTask);
			//Portal.update('takenTask', resp.takenTask);
			Portal.update('planing', resp.planing);
			Portal.update('auditPlan', resp.auditPlan);
			Portal.update('expiredTask', resp.expiredTask);
			Portal.update('deptTask', resp.deptTask);
			//Portal.update('needFeedBack', resp.needFeedBack);
			Portal.update('monitorUnfinishedTask', resp.monitorUnfinishedTask);
			Portal.update('monitorWeekTask', resp.monitorWeekTask);
			Portal.update('monitorMonthTask', resp.monitorMonthTask);
			Portal.update('dispatchFinished', resp.dispatchFinished);
			Portal.update('dispatchUnFinished', resp.dispatchUnFinished);
		}
	});
};

Ext.onReady(function() {
	Portal.main();
});